package com.cskaoyan._19collection._05list.arraylist;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author Macro_Ray
 * @since 2024/3/30 14:30
 */
public class ArrayListTest4 {
    public static void main(String[] args) {
        // 创建ArrayList对象
        ArrayList<Student> studentsList = new ArrayList<>();

        // 向ArrayList中添加Student对象，要求键盘录入
        Scanner sc = new Scanner(System.in);
        // 输入学生数量
        System.out.println("请输入学生的数量：" );
        int StudentCount = sc.nextInt();
        // 循环录入学生信息
        for (int i = 0; i < StudentCount; i++) {
            Scanner student = new Scanner(System.in);
            System.out.print("请输入第" + (i+1) + "个学生的姓名：" );
            String name = student.nextLine();
            System.out.print("请输入第" + (i+1) + "个学生的年龄：");
            int age = student.nextInt();
            // 创建Student对象并添加到ArrayList中
            studentsList.add(new Student(name, age));
        }

        // 遍历ArrayList，打印学生信息
        for (Student stu : studentsList){
            System.out.println("姓名：" + stu.getName() + "，年龄：" + stu.getAge());

        }
    }
}
